package com.bwie.groupon.service.impl;

import com.bwie.common.utils.R;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.Query;

import com.bwie.groupon.dao.GrouponDao;
import com.bwie.groupon.entity.GrouponEntity;
import com.bwie.groupon.service.GrouponService;


@Service("grouponService")
public class GrouponServiceImpl extends ServiceImpl<GrouponDao, GrouponEntity> implements GrouponService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<GrouponEntity> page = this.page(
                new Query<GrouponEntity>().getPage(params),
                new QueryWrapper<GrouponEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public R mygroup(Integer grouponId) {
        //条件查询
        GrouponEntity grouponEntity = baseMapper.selectById(grouponId);
        grouponEntity.setGroupStatus(1);
        //查询所有符合条件的
        baseMapper.updateById(grouponEntity);
        //不能为空
        return R.ok();
    }


    @Override
    public R myLists(Integer openGroupPeopleId) {
        QueryWrapper<GrouponEntity> w = new QueryWrapper<>();
        w.eq("open_group_people_id",openGroupPeopleId);
        List<GrouponEntity> entities = baseMapper.selectList(w);
        System.out.println("=="+entities);
        return R.ok().put("list",entities);
    }

}